package com.ybxy;

import java.util.HashMap;
import java.util.Map;

public class MapPractice {
    public static void main(String[] args) {
        Map<String,String> data = new HashMap<>();
        data.put("张三","A");
        data.put("李四","B");
        data.put("王五","C");
        data.put("赵六","C");
        data.put("赵六","B");
        data.put("小王1" , "A");
        data.put("小王2" , "B");
        data.put("小王3" , "A");
        data.put("小王4" , "A");
        data.put("小王5" , "C");
        data.put("小王6" , "A");
        data.put("小王7" , "C");
        count(data);

    }
    public static void count (Map<String,String> data){
        //创建一个新的map集合
        //遍历data集合
        Map<String,Integer> resultMap = new HashMap<>();
         data.forEach((key,value)->{
             boolean containsKey = resultMap.containsKey(value);
             if (containsKey){
                 //将老的值取出来+1,重新存入
                 Integer oldCount = resultMap.get(value);
                 resultMap.put(value,oldCount+1);
             }
             else {
                 resultMap.put(value,1);
             }
         });

         resultMap.forEach((key,value)->{
             System.out.println(key+"="+value);
         });
    }

}
